<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>扫码登录</title>
	<style type="text/css">
        *{padding: 0px;margin: 0px;}
        html,body{width: 100%;height: 100%;overflow:hidden;}
        .bg{position:absolute;left:0px;top:0px; width: 100%;height: 100%;z-index:-1}
        .body{width: 70%;height: 80%;margin:15% auto}
        .img{width:500px;height:250px;float:left;margin-top:40px}
        .ewm{width:272px;height:350px;float:right;background:#fff;text-align: center;}
	</style>

    <script src="__PUBLIC__/Home/js/jquery-2.1.4.min.js" type="text/javascript"></script>
    <script src="__PUBLIC__/Home/js/jquery.qrcode.min.js" type="text/javascript"></script>

</head>
<body>
	<div class="bg">
		<img style="width:100%;height:100%" src="__PUBLIC__/Home/image/bodybg.png">
	</div>
	    <div class="body">
		    <div class="img"><img style="width:420px;height:220px;" src="__PUBLIC__/Home/image/logo.png"></div>
		    <div class="ewm">
		    	<p style="color:#444;font-size:20px;margin-top:25px">登录</p>
		    	<div id="code" style="margin-top:20px"></div> 
		    	<p id="p-info" style="color:#848484;margin-top:35px;font-size:12px;">请使用微信小程序扫一扫登录</p>
		    </div>
		<div>
	</div>
</body>
<script type="text/javascript">
    $("#code").qrcode({ 
        width: 160, //宽度 
        height:160, //高度 
        text: "{$login_code}" //任意内容 
    }); 
   
    function monitorDoScanCode(){
        $.ajax({  
            url: "{:U('Index/monitorDoScanCode',array('login_code'=>$login_code))}",  
            dataType: "json",  
            async:true, 
            cache: false,  
            // error: function (XMLHttpRequest, textStatus, errorThrown) {  
            //     $("#state").append("[state: " + textStatus + ", error: " + errorThrown + " ]<br/>");  
            //     if (textStatus == "timeout") { // 请求超时  
            //         longPolling(); // 递归调用  
            //     } else { // 其他错误，如网络错误等  
            //         longPolling();  
            //     }  
            // },  
            success: function (data) {
                if(data.state == 0){
                	monitorDoScanCode();
                }else if(data.state == 1){
                    $("#p-info").text('登陆成功！正在进入...');
                    $("#p-info").css('color',"green");
                    var battle_id = data.battle_id;
                    setTimeout(function(){
                        var url = "{:U('Index/Index')}"+"&battle_id="+battle_id;
                        window.location.href = url;
                    },'100')
                }
            }  
        });  
    }
    window.onload=function(){ 
        monitorDoScanCode();
    }
   
</script>
</html>